package com.worker.ssm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.worker.ssm.mapper.EmployeeMapper;
import com.worker.ssm.pojo.Employee;
import com.worker.ssm.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class EmployeeServiceimpl implements EmployeeService {

    @Autowired
    EmployeeMapper employeeMapper;

    @Override
    public Employee getEmployeeById(Integer empId) {
        return employeeMapper.getEmployeeById(empId);
    }

    @Override
    public List<Employee> getAllEmployee() {
       return employeeMapper.getAllEmployee();
    }

    @Override
    public PageInfo<Employee> getEmployeePage(Integer pageNum) {
        // 开启分页功能 动态分页功能
        PageHelper.startPage(pageNum,5);
        // 查询所有的员工信息
        List<Employee> emps = employeeMapper.getAllEmployee();
        // 获取分页相关数据 navigatePages 导航分页 如当前第10页 以当前页为原点 显示前两页和后两页
        PageInfo<Employee> page = new PageInfo<>(emps,5);
        return page;
     }

    @Override
    public int insertEmployee(Employee employee) {
        return employeeMapper.insertEmployee(employee);
    }

    @Override
    public int deleteEmployee(Integer empId) {
        return employeeMapper.deleteEmployee(empId);
    }

    @Override
    public int updateEmployee(Integer empId,Employee emp) {
        return employeeMapper.updateEmployee(empId,emp);
    }
}
